/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.nyquistmeteocal.beans;

import it.nyquistmeteocal.boundary.EventManager;
import it.nyquistmeteocal.entity.Notification;
import it.nyquistmeteocal.boundary.NotificationManager;
import it.nyquistmeteocal.boundary.UserManager;
import it.nyquistmeteocal.entity.UserNotification;
import it.nyquistmeteocal.boundary.UserNotificationManager;
import it.nyquistmeteocal.entity.Event;
import java.io.IOException;
import java.io.Serializable;
import java.text.ParseException;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

/**
 *
 * @author gatb27
 */
@Named(value = "badweather")
@RequestScoped
public class ListBadWeather implements Serializable { 
    
    private static final long serialVersioneUID = 1L;
    
    @EJB
    private EventManager em;
    @EJB
    private NotificationManager nm;
    @EJB
    private UserManager um;
    @EJB
    private UserNotificationManager unm;
    
    private WeatherBean wb;
    private List<Event> editEvent;
    private List<Notification> badweatherList;
    private UserNotification usernotification = new UserNotification();

    public List<Notification> getBadweatherList() {
        return badweatherList;
    }

    public void setBadweatherList(List<Notification> badweatherList) {
        this.badweatherList = badweatherList;
    }
    
    @PostConstruct
    public void init() {
        
            badweatherList = nm.getBadWeather();
        
    }
    
    public String ReadBadWeather(Integer notid) {
        Integer unid = nm.findUserNotification(notid);
        usernotification.setId(unid);
        usernotification.setNotificationid(notid);
        String LogUser = um.getLoggedUser().getEmail();
        usernotification.setUsermail(LogUser);
        
        unm.deleteUserNotification(usernotification);
        
        return "showConfirm";
    }
    
    /* public String AcceptSuggestion(Integer notid) throws IOException, ParseException {
        System.out.println("The ID of the usernotification IS "+ notid); 
        editEvent = em.getEvents2(notid);
        Integer count = editEvent.size();
        System.out.println("The event to update is only one--> "+ count);
        int i;
        for(i=0; i<count; i++){
            Event currentEvent = editEvent.get(i);
            System.out.println("START ------ EVENT TO UPDATE INFORMATION --------");
            System.out.println(currentEvent.getEventname());
            System.out.println(currentEvent.getCity());
            System.out.println(currentEvent.getEventdate());
            System.out.println(currentEvent.getWeather());
            System.out.println("END ------ EVENT TO UPDATE INFORMATION --------");
            
            String nextdate = wb.firstDayNotRainy(currentEvent.getCity());
            System.out.println("The new date is --> " + nextdate);
            currentEvent.setEventdate(nextdate);
            currentEvent.setWeather(wb.weatherWithCityDate(currentEvent.getCity(), currentEvent.getEventname()));
            System.out.println("The new weather is --> " + currentEvent.getWeather());
            em.updateEvent(currentEvent);
            
        }
        
        return "showConfirm2";
    } */
    
    
    
}
